home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / include / bitmap.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  5.1 KB  |  253 lines

  1. /*
  2.  *   $RCSfile: bitmap.h,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:55:42 $      
  5.  */ 
  6. #ifndef __BITMAP_H__
  7. #define __BITMAP_H__
  8. /**********************************************************************
  9. * EXODUS Database Toolkit Software
  10. * Copyright (c) 1991 Computer Sciences Department, University of
  11. *                    Wisconsin -- Madison
  12. * All Rights Reserved.
  13. *
  14. * Permission to use, copy, modify and distribute this software and its
  15. * documentation is hereby granted, provided that both the copyright
  16. * notice and this permission notice appear in all copies of the
  17. * software, derivative works or modified versions, and any portions
  18. * thereof, and that both notices appear in supporting documentation.
  19. *
  20. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  21. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  22. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  23. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  24. *
  25. * The EXODUS Project Group requests users of this software to return 
  26. * any improvements or extensions that they make to:
  27. *
  28. *   EXODUS Project Group 
  29. *     c/o David J. DeWitt and Michael J. Carey
  30. *   Computer Sciences Department
  31. *   University of Wisconsin -- Madison
  32. *   Madison, WI 53706
  33. *
  34. *     or exodus@cs.wisc.edu
  35. *
  36. * In addition, the EXODUS Project Group requests that users grant the 
  37. * Computer Sciences Department rights to redistribute these changes.
  38. **********************************************************************/
  39. /*
  40.  *    this structure is used to allocate bits from the bitmap
  41.  */
  42. typedef struct {
  43.  
  44.     UFOUR        bitOffset;
  45.     UFOUR        bitCount;
  46.     UFOUR        absoluteBitOffset;    
  47.     UFOUR        word;
  48.     SHORTPID    page;
  49.     GROUPLINK    *groupLink;
  50.  
  51. } BITCONTEXT;
  52.  
  53.  
  54. /*
  55.  *    define the maximum number of pages that can be allocated
  56.  *    at a single time.  Right now this is calculated from
  57.  *    the maximum allocation of a single page.  This MUST
  58.  *    be changed if we go to an extent allocation mechanism
  59.  */
  60. #define MAX_ALLOC_PAGES        (100)
  61.  
  62.  
  63. /*
  64.  *    define the maximum number of words that an allocated block can span
  65.  */
  66. #define MAX_BIT_WORD_SPAN    ((MAX_ALLOC_PAGES/BITSPERWORD) + 2)
  67.  
  68.  
  69. /*
  70.  *    this holds the context for a free run which may span pages
  71.  */
  72. typedef struct {
  73.  
  74.     LISTELEMENT        list;
  75.     BITCONTEXT        bitContext[MAX_BIT_WORD_SPAN];
  76.     TWO                contextIndex;
  77.     MAGIC            magic;
  78.  
  79. } FREECONTEXT;
  80.  
  81.  
  82. /*
  83.  *    define the context magic number
  84.  */
  85. #define FREECONTEXT_MAGIC    0xfad5134c
  86.  
  87. /*
  88.  *    define magic number checks
  89.  */
  90. #if MAGIC_CHECKING IS_ENABLED
  91.  
  92.  
  93. #define INIT_FREECONTEXT_MAGIC(_context)                \
  94.     _context->magic = FREECONTEXT_MAGIC;
  95.  
  96.  
  97. #define CHECK_FREECONTEXT_MAGIC(_context)                \
  98.                                                         \
  99.     if ((_context)->magic != FREECONTEXT_MAGIC)    {        \
  100.         SM_ERROR(TYPE_FATAL, esmINTERNAL);                \
  101.     }
  102.  
  103.  
  104. #else
  105.  
  106.  
  107. #define INIT_FREECONTEXT_MAGIC(_context)
  108.  
  109. #define CHECK_FREECONTEXT_MAGIC(_context)
  110.  
  111.  
  112. #endif
  113.  
  114.  
  115. /*
  116.  *    define a structure that holds a pid, grouplink and refcount
  117.  */
  118. typedef struct    {
  119.  
  120.     LISTELEMENT        list;
  121.     GROUPLINK        *groupLink;
  122.     PID                pid;
  123.     TWO                fixCount;
  124.     FOUR            bitsChanged;
  125.     MAGIC            magic;
  126. } PAGECONTEXT;
  127.  
  128.  
  129. /*
  130.  *    define the context magic number
  131.  */
  132. #define PAGECONTEXT_MAGIC    0x200a243c
  133.  
  134. /*
  135.  *    define magic number checks
  136.  */
  137. #if MAGIC_CHECKING IS_ENABLED
  138.  
  139.  
  140. #define INIT_PAGECONTEXT_MAGIC(_context)                \
  141.     _context->magic = PAGECONTEXT_MAGIC;
  142.  
  143.  
  144. #define CHECK_PAGECONTEXT_MAGIC(_context)                \
  145.                                                         \
  146.     if ((_context)->magic != PAGECONTEXT_MAGIC)    {        \
  147.         SM_ERROR(TYPE_FATAL, esmINTERNAL);                \
  148.     }
  149.  
  150.  
  151. #else 
  152.  
  153.  
  154. #define INIT_PAGECONTEXT_MAGIC(_context)
  155.  
  156. #define CHECK_PAGECONTEXT_MAGIC(_context)
  157.  
  158.  
  159. #endif
  160.  
  161.  
  162. /*
  163.  *    define the number of pages in the bitmap page group
  164.  */
  165. #define BITMAP_GROUP_SIZE    8
  166.  
  167.  
  168. /*
  169.  *    get the page given the bit
  170.  *    these are only applicable for bitmap routines
  171.  *    note that these depend on the bitmap usable
  172.  *    size being a multiple of 4 bytes
  173.  */
  174. #define BIT_TO_PAGE(_bit)        \
  175.     (((ulong) (_bit)) / (BITMAP_USABLESIZE * 8))
  176.  
  177.  
  178. /*
  179.  *    get the bit offset in the page
  180.  */
  181. #define BIT_IN_PAGE(_bit)        \
  182.     (((ulong) (_bit)) % (BITMAP_USABLESIZE * 8))
  183.  
  184.  
  185. /*
  186.  *    get the word offset given the bit
  187.  */
  188. #define BIT_TO_WORD(_bit)                    \
  189.     (((ulong) _bit) >> 5)
  190.  
  191.  
  192. /*
  193.  *    define the byte offset given the bit
  194.  */
  195. #define BIT_TO_BYTE(_bit)                    \
  196.     (((ulong) _bit) >> 3)
  197.  
  198.  
  199. /*
  200.  *    get the offset in the word given the bit
  201.  */
  202. #define BIT_IN_WORD(_bit)                    \
  203.     (_bit & 0x1f)
  204.  
  205.  
  206. /*
  207.  *    get the offset in the byte given the bit
  208.  */
  209. #define BIT_IN_BYTE(_bit)                    \
  210.     (_bit & 0x07)
  211.  
  212.  
  213. /*
  214.  *    define the offset to the given bits
  215.  */
  216. #define PAGE_TO_BIT(_page)        \
  217.     (((ulong) _page) * (BITMAP_USABLESIZE * 8))
  218.  
  219.  
  220. /*
  221.  *    define the number of words in the page
  222.  */
  223. #define WORDS_IN_PAGE     (((ulong) BITMAP_USABLESIZE) / 4)
  224.  
  225.  
  226. /*
  227.  *    define the number of bits before the word
  228.  */
  229. #define WORD_TO_BIT(_word)                    \
  230.     (((ulong) _word) << 5)
  231.  
  232.  
  233. /*
  234.  *    define the number of words in the page
  235.  */
  236. #define BITS_IN_PAGE     (((ulong) BITMAP_USABLESIZE) * 8)
  237.  
  238.  
  239. /*
  240.  *    define a mask that gets the most significant bit
  241.  */
  242. #define MSB_MASK    0x80000000
  243. #define ALLSET_MASK    0xffffffff
  244.  
  245.  
  246. /*
  247.  *    define the maximum number of pages that an allocated block can span
  248.  */
  249. #define MAX_BIT_PAGE_SPAN(_allocBits)            \
  250.     (((_allocBits)/(BITMAP_USABLESIZE * 8)) + 2)
  251.  
  252. #endif __BITMAP_H__
  253.